package com.itzz.spring_zhoneHeng.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itzz.spring_zhoneHeng.pojo.Book;
import com.itzz.spring_zhoneHeng.pojo.Chapters;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookDao extends BaseMapper<Book> {
    //查询所有的书籍
    List<Book>  queryAllBook(Book book);
    //查询所有的类别
    @Select("select distinct category from book b")
    List<Book>  queryAllCategory();

    //修改书籍
    int updateBook(Book book);

    //根据id查询书籍
    @Select("SELECT id,book_name,author,introduce,path,`read`,intestate,vip FROM book WHERE id=#{id}")
    Book queryById(Integer id);

    //添加书籍
//    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int addBook(Book book);


    //根据书籍id放回b_c表中的classid
    @Select("select bc.classid from book b join b_c bc on b.id=bc.bid " +
            "join classification c on c.id=bc.classid where bc.bid=#{bid}")
    Integer queryClassId(Integer bid);


    //根据书架的id查询书籍的id
    @Select("select b.id from book b join b_bs bs on b.id=bs.bookid where bs.bsid=#{id}")
    Integer queryBookId(Integer id);


    //删除book 关联的表B_C  根据bid删除
    @Update("delete from b_c where bid=#{bid}")
    int delB_C(Integer bid);


    //根据bookId  查询相应的  简介
    @Select("select introduce from book where id=#{bookId}")
    String selectIntroduce(Integer bookId);

    //根据bookId  查询b_bs中集合 bsid
    @Select("select bsid from b_bs where bookid=#{bookId}")
    List<Integer> selectBsid(Integer bookId);


    //删除book 关联的表b_bs  根据bookid删除
    @Delete("delete from b_bs where bookid=#{bookId}")
    int delB_BS(Integer bookId);

    //删除b_chap 表  根据bookid删除
    @Delete("delete from b_chap where bookid=#{bookId}")
    int delB_CHAP(Integer bookId);

    //删除书籍时,删除订单的关联表 根据bookid 删除o_b表
    @Delete("delete from o_b where bookid=#{bookId}")
    int delO_B(Integer bookId);

    //根据chapters 查询表chapters 中的id Chapters
//    @Select("select id from chapters where id=#{chapid}")
    List<Chapters> Chapters(Integer[] chapIds);

    //根据书籍id查询书籍的所有信息
    @Select("select * from book where id=#{bookId}")
    Book queryByBook(Integer bookId);

}
